#!/bin/bash

# This postservice hook is needed when the Docker module is installed.

set -e

####
## Functions
####

function docker_module() {
    MODULE_EXISTS=$(dpkg -l | grep -qo  'ii  zentyal-docker ' || true)
    MODULE_STATUS=$(perl -MEBox::Global -e "print EBox::Global->getInstance()->modInstance('docker')->isEnabled();")
    if [[ -z ${MODULE_EXISTS} && ${MODULE_STATUS} -eq 1 ]]; then
        # Needed to avoid issues with Systemd
        sleep 5
        systemctl restart docker
    fi
}


####
## Calls
####

docker_module

exit 0
